/*
    kOTF Open Trace Format - a library for generating execution traces.
    Copyright 2012 Daniel K. O.

    kOTF is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    kOTF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with kOTF.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KOTF_EVENTS_H
#define KOTF_EVENTS_H

#include <kotf/Types.hpp>

namespace kotf {
    /** \brief struct containing events generated during the trace.

        It has the size of 5 64-bit words.
    */
    struct Event {

        /** \brief represents the timestamp of an event.
         */
        typedef uint64_t TimeStamp;

        enum Type 
        {
            StreamBegin,
            StreamEnd,
            EnterState,
            LeaveState,
            UpdateCounter,
            SendMsg,
            BroadcastMsg,
            RecvMsg
        };

        struct Base {
            TimeStamp timestamp;
            Type type;
        } __attribute__((aligned (8)));

        struct Stream : Base {
            uint64_t id;
            uint64_t parent; ///< valid only if type == StreamBegin; defaults to InvalidId
            uint64_t tag; ///< optional tag, defaults to zero
        };

        struct State : Base {
            uint64_t id;
            uint64_t _padding_;
            uint64_t tag; ///< optional tag, defaults to zero
        };

        struct Counter : Base {
            uint64_t id;
            uint64_t value;
            uint64_t tag; ///< optional tag, defaults to zero
        };

        struct Message : Base {
            uint64_t chan;
            uint64_t len;
            uint64_t tag; ///< optional tag, defaults to zero
        };

        union {
            Base base;
            Stream stream;
            State state;
            Counter counter;
            Message message;
        };
    };

}

#endif
